package m1;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.util.Scanner;

public class Producer {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        // 创建生产者实例
        DefaultMQProducer p = new DefaultMQProducer("producerGroup1");
        // 设置 name server 地址
        p.setNamesrvAddr("192.168.64.141:9876");
        // 启动生产者（连接服务器）
        p.start();
        // 创建 Message 对象封装消息数据
        // 发送消息
        while (true) {
            System.out.print("输入消息：");
            String s = new Scanner(System.in).nextLine();
            /*
            Topic 相当于消息的一级分类
            Tag   相当于消息的二级分类
             */
            Message msg = new Message("Topic1", "Tag1", s.getBytes());
            msg.setDelayTimeLevel(3);

            SendResult r = p.send(msg);
            System.out.println(r);
        }
    }
}
